/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package percussiongenerator.gui;

import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JColorChooser;
import javax.swing.JLabel;
import org.jfonia.connect5.basics.BasicValueNode;
import org.jfonia.connect5.basics.MutableValueNode;

/**
 *
 * @author Jannes Plyson
 */
public class ColorChooserLabel extends JLabel{
    MutableValueNode colorNode;

    public ColorChooserLabel(Color color){
        super("    ");
        colorNode = new BasicValueNode<Color>(color);
        this.setOpaque(true);
        this.setBackground(color);
        final JLabel thisObject = this;
        this.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if(e.getClickCount() == 2){
                    Color color = JColorChooser.showDialog(null, "Choose color", thisObject.getBackground());
                    if(color != null){
                        thisObject.setBackground(color);
                        colorNode.setValue(color);
                    }
                }
            }
        });
    }

    public MutableValueNode<Color> getColorNode(){
        return colorNode;
    }
}
